package com.xiaohe66.web.domain.birth.agg;

import com.xiaohe66.web.domain.account.value.AccountId;
import com.xiaohe66.web.domain.birth.value.BirthdayDate;
import com.xiaohe66.web.domain.birth.value.BirthdayId;
import com.xiaohe66.web.domain.birth.value.BirthdayName;
import com.xiaohe66.web.domain.birth.value.BirthdayType;
import com.xiaohe66.web.domain.birth.value.BirthdayValue;
import com.xiaohe66.web.integration.domain.Aggregate;
import com.xiaohe66.web.integration.value.DayValue;
import com.xiaohe66.web.integration.value.MonthValue;
import com.xiaohe66.web.integration.value.YearValue;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;

import java.util.Objects;

/**
 * @author xiaohe
 * @since 2023-07-12 15:41
 */
@Builder
@Getter
@ToString
@AllArgsConstructor
public class Birthday implements Aggregate<Birthday, BirthdayId> {

    @NonNull
    private final BirthdayId id;

    @NonNull
    private final AccountId createId;

    private BirthdayName name;

    private BirthdayType birthType;
    private YearValue year;
    private MonthValue month;
    private DayValue day;

    public BirthdayDate toBirthdayDate() {
        return new BirthdayDate(birthType, month, day, year);
    }

    public BirthdayValue toBirthdayValue() {
        return new BirthdayValue(birthType, month, day);
    }

    @Override
    public boolean hasSameRootAttribute(Birthday other) {
        return other != null &&
                Objects.equals(name, other.name) &&
                Objects.equals(birthType, other.birthType) &&
                Objects.equals(year, other.year) &&
                Objects.equals(month, other.month) &&
                Objects.equals(day, other.day);
    }
}
